package com.itheima.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.constants.WemediaConstants;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.itheima.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yunfei
 * @date 2022年10月17日 11:07
 */
@RestController
@RequestMapping("/api/v1/news")
public class NewsController {

    @Autowired
    private WmNewsService newsService;

    /**
     * 自媒体端文章的列表查询
     *
     * @param pageReqDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult newsList(@RequestBody WmNewsPageReqDto pageReqDto) {
        return newsService.newsList(pageReqDto);
    }


    /**
     * 自媒体端文章的发布
     *
     * @param newDto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult newsSubmit(@RequestBody WmNewsDto newDto) throws Exception {
        return newsService.newsSubmit(newDto);
    }

    /**
     * 文章上下架
     * @param dto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return newsService.downOrUp(dto);
    }

    @PostMapping("/list_vo")
    public ResponseResult findList(@RequestBody NewsAuthDto dto){
        return newsService.findList(dto);
    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id){
        return newsService.findWmNewsVo(id);
    }

    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto){
        return newsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_PASS,dto);
    }

    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto){
        return newsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_FAIL,dto);
    }
}
